import server from '../server'

// 定义请求学生列表信息的接口
var getStudents = function(params) {
    return new Promise((resolve, reject) => {
        server.get('/list.json').then(res => {
            // 当 pageIndex = 1 pageSize = 10 获取 0 - 9 的数据
            // 当 pageIndex = 2 pageSize = 10 获取 10 - 19 的数据
            // 当 pageIndex = 3 pageSize = 10 获取 20 - 29 的数据
            var list = res.data
            var len = list.length
            var start = (params.pageIndex - 1) * params.pageSize
            var end = params.pageIndex * params.pageSize
            // splice 返回值是删除的数据的集合
            var newArr = list.splice(start, end)

            var obj = {
                totle: len,
                newArr
            }
            resolve(obj)
        })
    })
}


// 登录接口
var login = function(params) {
    return new Promise((resolve, reject) => {
        server({
            method: "post",
            url: 'https://api.it120.cc/small4/user/m/login?deviceId=007&deviceName=monkey',
            params: params
        }).then(res => {
            resolve(res.data.data)
            // console.log(res)
        })
    })
}
export {
    getStudents,
    login
}